/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.i.kotionokyurievna.jewelry.domain.person;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import ua.i.kotionokyurievna.jewelry.domain.user.User;

/**
 *
 * @author Kateryna_Reznik
 */
public class Person extends User{
    private int personId;
    private String firstName;
    private String lastName;
    private Date birthDate;
    private String telephone;
    private String email;
    private Gender gender;
    
    
    public Person(){
        
    }

    public Person(String firstName, String lastName, Date birthDate, 
            String telephone, String email, Gender gender, User user) {
        super(user);
        this.firstName = firstName;
        this.lastName = lastName;
        this.birthDate = birthDate;
        this.telephone = telephone;
        this.email = email;
        this.gender = gender;
    }

    public Person(int personId, String firstName, String lastName, 
            Date birthDate, String telephone, String email, 
            Gender gender, User user) {
        super(user);
        this.personId = personId;
        this.firstName = firstName;
        this.lastName = lastName;
        this.birthDate = birthDate;
        this.telephone = telephone;
        this.email = email;
        this.gender = gender;
    }
    
    public Person ( Person another ){
        if ( another != null ){
            this.personId = another.personId;
            this.firstName = another.firstName;
            this.lastName = another.lastName;
            this.birthDate = another.birthDate;
            this.telephone = another.telephone;
            this.email = another.email;
            this.gender = another.gender;
        }
    }
     
    public int getPersonId() {
        return personId;
    }

    public String getFirstName() {
        return firstName;
    }
    
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }
    
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Date getBirthDate() {
        return birthDate;
    }
    
    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }

    public String getTelephone() {
        return telephone;
    }
    
    public boolean setTelephone(String telephone) {
        Pattern p = Pattern.compile("(\\+){1}([0-9]){12}");
        Matcher m = p.matcher(telephone);
        if ( m.matches() ){
            this.telephone = telephone;
            return true;
        }
        else{
            if ( telephone == null ){
                this.telephone = "";
            }
        }
        return false;
    }

    public String getEmail() {
        return email;
    }
    
    public boolean setEmail(String email) {
        
        Pattern p = Pattern.compile(".*(@){1}.*");
        Matcher m = p.matcher(email);
        if ( m.matches() ){
            this.email = email;
            return true;
        }
        else{
            if ( email == null ){
                this.email = email;
            }
        }
        return false;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    @Override
    public String toString() {
        return "Person{" + "personId=" + personId +  
                ", firstName=" + firstName + ", lastName=" + lastName + 
                ", birthDate=" + birthDate + ", telephone=" + telephone + 
                ", email=" + email + ", gender=" + gender + '}';
    }    
}
